<?php
define('FPDF_FONTPATH','font/');
require_once('fpdf.php');
require_once('gisp_admincon.php');
require_once('qrcode.class.php');
require_once("Connections/coneccionRatania.php");
require_once("Connections/funciones_pg.php");
//include_once('rotation.php');



	
	
class PDF extends FPDF{

var $angle=0;
var $javascript;
var $n_js;

	function IncludeJS($script) {
		$this->javascript=$script;
	}

	function _putjavascript() {
		$this->_newobj();
		$this->n_js=$this->n;
		$this->_out('<<');
		$this->_out('/Names [(EmbeddedJS) '.($this->n+1).' 0 R]');
		$this->_out('>>');
		$this->_out('endobj');
		$this->_newobj();
		$this->_out('<<');
		$this->_out('/S /JavaScript');
		$this->_out('/JS '.$this->_textstring($this->javascript));
		$this->_out('>>');
		$this->_out('endobj');
	}


function AutoPrint($dialog=false)
{
	//Open the print dialog or start printing immediately on the standard printer
	$param=($dialog ? 'true' : 'false');
	$script="print($param);";
	$this->IncludeJS($script);
}

function AutoPrintToPrinter($server, $printer, $dialog=false)
{
	//Print on a shared printer (requires at least Acrobat 6)
	$script = "var pp = getPrintParams();";
	if($dialog)
		$script .= "pp.interactive = pp.constants.interactionLevel.full;";
	else
		$script .= "pp.interactive = pp.constants.interactionLevel.automatic;";
	$script .= "pp.printerName = '\\\\\\\\".$server."\\\\".$printer."';";
	$script .= "print(pp);";
	$this->IncludeJS($script);
}


	function _putresources() {
		parent::_putresources();
		if (!empty($this->javascript)) {
			$this->_putjavascript();
		}
	}

	function _putcatalog() {
		parent::_putcatalog();
		if (!empty($this->javascript)) {
			$this->_out('/Names <</JavaScript '.($this->n_js).' 0 R>>');
		}
	}
	

function Rotate($angle,$x=-1,$y=-1)
{
	if($x==-1)
		$x=$this->x;
	if($y==-1)
		$y=$this->y;
	if($this->angle!=0)
		$this->_out('Q');
	$this->angle=$angle;
	if($angle!=0)
	{
		$angle*=M_PI/180;
		$c=cos($angle);
		$s=sin($angle);
		$cx=$x*$this->k;
		$cy=($this->h-$y)*$this->k;
		$this->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
	}
}

function _endpage()
{
	if($this->angle!=0)
	{
		$this->angle=0;
		$this->_out('Q');
	}
	parent::_endpage();
}

function RotatedText($x,$y,$txt,$angle)
{
    //Text rotated around its origin
    $this->Rotate($angle,$x,$y);
    $this->Text($x,$y,$txt);
    $this->Rotate(0);
}

function RoundedRect($x, $y, $w, $h, $r, $style = '')
    {
        $k = $this->k;
        $hp = $this->h;
        if($style=='F')
            $op='f';
        elseif($style=='FD' || $style=='DF')
            $op='B';
        else
            $op='S';
        $MyArc = 4/3 * (sqrt(2) - 1);
        $this->_out(sprintf('%.2F %.2F m',($x+$r)*$k,($hp-$y)*$k ));
        $xc = $x+$w-$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2F %.2F l', $xc*$k,($hp-$y)*$k ));

        $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
        $xc = $x+$w-$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2F %.2F l',($x+$w)*$k,($hp-$yc)*$k));
        $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
        $xc = $x+$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2F %.2F l',$xc*$k,($hp-($y+$h))*$k));
        $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
        $xc = $x+$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2F %.2F l',($x)*$k,($hp-$yc)*$k ));
        $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
        $this->_out($op);
    }

    function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
    {
        $h = $this->h;
        $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $x1*$this->k, ($h-$y1)*$this->k,
            $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
    }
	
	function Header(){
		//datos SQL
		global $login;
		global $centro_costo;
		global $nom_oficina;
		global $cod_actproy;
		global $des_actproy;
		global $cod_nemonico;
		global $des_nemonico;
		global $title;
		global $nro_nec;
		global $ano_eje;
		global $fch_nec;
		global $tipo_bien;
		global $reqs_anuales;			
		global $topIni;
		global $marIni;
		global $wcel;
		global $empresaM;
		global $distrito;
		global $departamento;
		global $provincia;
		global $logoCabIzq;
		global $logoSupP1;
		global $logoSupP2;
		global $logoSupP3;
		global $logoSupP4;
		global $marcaAguaP1;
		global $marcaAguaL1;
		global $marcaAguaL2;
		global $marcaAguaL3;
		global $marcaAguaL4;global $marcaAguaP2;
		global $marcaAguaP3;
		global $marcaAguaP4;
		global $marcaDeAgua;
		global $repositorioFirmas;
		global $RUC;
		global $numero_recibo;
		global $codigoContrib;
		global $nombreContrib;
		global $nroDoc;
		global $direccionContrib;
		global $cajero;
		global $fechaEmision;
		global $fechaImpresion;
		global $fechaProyectado1;
                global $fechaIni;
                global $fechaFin;
		global $err;
		global $fechaRecargos;
		global $usuario;
		global $colCab;
		global $colSubCab;
                global $subTipoReporte;
                global $tipoReporte;
                global $nroCaja;
 global $nombreccajero;
 global $cnumini;
 global $cnumfin;
 global $nmonape;
 global $nmonval; 
 global $nmonanu; 
 global $nmonent; 
 global $nmondif; 
 global $vobserv; 
 global $fechaapertura; 
 global $fechacierre;
 global $idApertura;
 global $cidUser;
 global $TotalOpe;
 global $TotalAnulado;
 global $TotalNEfectivo;
 global $TotalEfectivo;
 global $TotalMontoDif;
 
 
		
		$tamInfoCuadro = -16;
                $posInfoCuadro = 26;
                $tamInfoCuadro2 = -9;
                $posInfoCuadro2 = 9;
                $tamcabecera=30;
		
		$lw = $marIni;
		$ln = $topIni;
		$ls = 3;
		$lh = 0;
		//MArca de Agua
		$this->Image('../img/marca/escudomarcaagua4.png',$marcaAguaL1-20,$marcaAguaL2,$marcaAguaL3+50,$marcaAguaL4+50,'PNG');
		
		//Logo
		$this->SetFont('arial','B',9);
		//$this->SetFillColor(206,232,212); //verde agua
		$this->SetFillColor(188,217,190); //verde agua
		$this->SetXY($lw-10,$lh);
		$this->Cell(220,8,"",0,1,'L',true);
		$this->SetFillColor(243);
		$this->SetFont('arial','B',9);
		$this->SetXY($lw-10,$lh);
		$this->MultiCell(50,8,'Calle 9 de Junio Nro 100',1,'C');
		$this->SetXY($lw+40,$lh);
		$this->MultiCell(50,8,'Puente Piedra - Lima - Peru',1,'C');
		$this->SetXY($lw+90,$lh);
		$this->MultiCell(50,8,'www.munipuentepiedra.gob.pe',1,'C');
		$this->SetXY($lw+140,$lh);
		$this->MultiCell(60,8,'Telefono 219 6200 - 219 6201',1,'C');
		//$this->RoundedRect(-10, 0, 220, 8, 1,'S');
		$this->Image('../img/marca/munipuentepiedra.png',$lw,$ln,62,18,'PNG');
		
		//$this->SetFillColor(145,185,154); //verde agua
		$this->SetFillColor(255);
		$lh = $lh+9;
		$this->SetXY($lw+70,$lh);
		$this->Cell(160,12,"",0,1,'L',true);
		$this->SetFont('arial','B',14);
		$this->SetXY($lw+60,$lh);
		$this->MultiCell(140,10,'SUB GERENCIA DE TESORERIA',0,'C');
		
		
		//definimos  ancho y color de rectangulo
		$lh = $lh+20;
		$this->SetLineWidth(0.3);
		$this->SetFillColor(255);
		$this->RoundedRect($lw-5, $lh, 110+$tamcabecera, 27, 1, '');
		$this->SetFont('arial','B',12);
		$this->SetXY($lw+20,$lh+2);
		$this->MultiCell(120,5,$tipoReporte,0,'J');
		$this->SetFont('arial','B',12);
		$this->SetXY($lw+10,$lh+12);
		$this->MultiCell(120,5,$subTipoReporte,0,'J');
                $this->SetFont('arial','B',12);
		$this->SetXY($lw+10,$lh+18);
		$this->MultiCell(120,5,$nombreccajero,0,'J');
		
		//$qrcode = new QRcode(utf8_encode('Hola'), $err);
		//$qrcode->disableBorder();
		
		//aqui va el codigo de barras
		//$qrcode->displayHTML();
		//$this->SetXY($lw+10,$lh+12);
		//$qrcode->displayPNG(50);
		//$this->Image(,$lw,$ln,62,18,'PNG');
		
		//$this->SetXY($lw,$lh + 17 );
		$this->Image('../img/marca/barraBoucher_2dat.gif',$lw-3,$lh+12,13,13,'GIF','');
		
                //$posInfoCuadro
                //+$tamInfoCuadro
                $ls = 6;
		//$this->RoundedRect($lw+110, $lh-$ls, 85, 27, 1, '');
                
		
		
		$this->SetFont('arial','',8);
		$this->SetXY($lw+110+$posInfoCuadro,$lh+8-$ls);
		$this->Cell(42+$tamInfoCuadro,8,"",1,1,'L',true);
		$this->SetXY($lw+112+$posInfoCuadro,$lh+9-$ls);
		$this->MultiCell(40+$tamInfoCuadro,5,'Desde',0,'J');
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+8-$ls);
		$this->Cell(43+$tamInfoCuadro2,8,"",1,1,'L',true);
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+9-$ls);
		$this->SetFont('f25bankprinter','',10);
		$this->MultiCell(43+$tamInfoCuadro2,5,$fechaIni,0,'R');
                
                $this->SetFont('arial','',8);
		$this->SetXY($lw+110+$posInfoCuadro,$lh+14-$ls);
		$this->Cell(42+$tamInfoCuadro,8,"",1,1,'L',true);
		$this->SetXY($lw+112+$posInfoCuadro,$lh+15-$ls);
		$this->MultiCell(40+$tamInfoCuadro,5,'Hasta',0,'J');
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+14-$ls);
		$this->Cell(43+$tamInfoCuadro2,8,"",1,1,'L',true);
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+15-$ls);
		$this->SetFont('f25bankprinter','',10);
		$this->MultiCell(43+$tamInfoCuadro2,5,$fechaFin,0,'R');
		
		
		$this->SetFont('arial','',8);
		$this->SetXY($lw+110+$posInfoCuadro,$lh+20-$ls);
		$this->Cell(42+$tamInfoCuadro,6,"",1,1,'L',true);
		$this->SetXY($lw+112+$posInfoCuadro,$lh+21-$ls);
		$this->MultiCell(40+$tamInfoCuadro,4,'Usuario Imprime',0,'J');
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+20-$ls);
		$this->Cell(43+$tamInfoCuadro2,6,"",1,1,'L',true);
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+21-$ls);
		$this->SetFont('f25bankprinter','',10);
		$this->MultiCell(43+$tamInfoCuadro2,4,$usuario,0,'R');
		
		$this->SetFont('arial','',8);
		$this->SetXY($lw+110+$posInfoCuadro,$lh+26-$ls);
		$this->Cell(42+$tamInfoCuadro,7,"",1,1,'L',true);
		$this->SetXY($lw+112+$posInfoCuadro,$lh+27-$ls);
		$this->MultiCell(40+$tamInfoCuadro,4,'Fecha Impresion',0,'J');
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+26-$ls);
		$this->Cell(43+$tamInfoCuadro2,7,"",1,1,'L',true);
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+27-$ls);
		$this->SetFont('f25bankprinter','',7);
		$this->MultiCell(43+$tamInfoCuadro2,4,$fechaImpresion,0,'R');
		
                $lh = $lh +35;
		
               


		$ls=-5;
                $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,'CAJA',0,'C');
		
                $ls = $colSubCab[0][0]*2-5;
                $this->SetFillColor(255,255,255); //Blanco
                $this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,$nroCaja,0,'C');
		
		$ls = $colSubCab[0][0]*2+$colSubCab[0][0]*2-5;
                 $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[3]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colCab[3]*2,3,  'Nombre y Apellidos',0,'C');
		
		$ls = $colSubCab[0][0]*2+$colSubCab[0][0]*2+$colCab[3]*2-5;
                $this->SetFillColor(255,255,255); //Blanco
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[5],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colCab[5],3, $cidUser." - ".$nombreccajero,0,'C');	
                
                $lh = $lh +5;
		
		$ls=-5;
                $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,'Apertura',0,'C');
		
                $ls = $colSubCab[0][0]*2-5;
                $this->SetFillColor(255,255,255); //Blanco
                $this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,$idApertura,0,'C');
		
		$ls = $colSubCab[0][0]*4-5;
                 $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,  'Recibo. Ini',0,'C');
		
		$ls = $colSubCab[0][0]*6-5;
                $this->SetFillColor(255,255,255); //Blanco
		$this->SetFont('arial','',7);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3, $cnumini,0,'C');
                
                $ls = $colSubCab[0][0]*8-5;
                 $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,  'Recibo. Fin',0,'C');
		
		$ls = $colSubCab[0][0]*10-5;
                $this->SetFillColor(255,255,255); //Blanco
		$this->SetFont('arial','',7);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3, $cnumfin,0,'C');
                
                $ls = $colSubCab[0][0]*12-5;
                 $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0],3,  'F Ape',0,'C');
		
		$ls = $colSubCab[0][0]*13-5;
                $this->SetFillColor(255,255,255); //Blanco
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*3,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*3,3, $fechaapertura,0,'C');
                
                $ls = $colSubCab[0][0]*16-5;
                 $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0],3,  'F Fin',0,'C');
		
		$ls = $colSubCab[0][0]*17-5;
                $this->SetFillColor(255,255,255); //Blanco
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*3,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*3,3, $fechacierre,0,'C');
                
                $lh = $lh +5;
		
		$ls=-5;
                $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,'Total Ope',0,'C');
		
                $ls = $colSubCab[0][0]*2-5;
                $this->SetFillColor(255,255,255); //Blanco
                $this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,  number_format( $TotalOpe,2,',',' ') ,0,'C');
		
		$ls = $colSubCab[0][0]*4-5;
                 $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,  'M Anulado',0,'C');
		
		$ls = $colSubCab[0][0]*6-5;
                $this->SetFillColor(255,255,255); //Blanco
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3, number_format($TotalAnulado,2,',',' '),0,'C');
                
                $ls = $colSubCab[0][0]*8-5;
                 $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,  'Total Efe.',0,'C');
		
		$ls = $colSubCab[0][0]*10-5;
                $this->SetFillColor(255,255,255); //Blanco
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3, number_format($TotalEfectivo,2,',',' '),0,'C');
                
                $ls = $colSubCab[0][0]*12-5;
                 $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,  'Total NEfe.',0,'C');
		
		$ls = $colSubCab[0][0]*14-5;
                $this->SetFillColor(255,255,255); //Blanco
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3, number_format($TotalNEfectivo,2,',',' '),0,'C');
                
                $ls = $colSubCab[0][0]*16-5;
                 $this->SetFillColor(188,217,190); //verde agua
		
		
		$TotalMontoDif = (($TotalNEfectivo+$TotalEfectivo)+$TotalAnulado)-$TotalOpe ;
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,  'Total Dif.',0,'C');
		
		$ls = $colSubCab[0][0]*18-5;
                $this->SetFillColor(255,255,255); //Blanco
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3, number_format($TotalMontoDif,2,',',' '),0,'C');
                
                $lh = $lh +5;
		
		$ls=-5;
                
		$this->SetFont('arial','B',8);
                $this->SetFillColor(188,217,190); //verde agua
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*20,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*20,3,'Cierre Diario Cajero .: Total Operaciones Validas : '.
                        number_format($TotalOpe-$TotalAnulado,2,',',' ').
                        ' .: Total Reportado : '.
                        number_format($TotalEfectivo+$TotalNEfectivo,2,',',' '),0,'C');
		
                $lh = $lh +5;
                $ls = -5;
                $this->SetFillColor(255,255,255); //Blanco
                $this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*20,40,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
                
                $vobserv = ereg_replace("<p>", "",$vobserv);
                $vobserv = ereg_replace("</p>", "",$vobserv);
                $vobserv = ereg_replace("[\n|\r|\n\r]", " ", $vobserv);
		$this->MultiCell($colSubCab[0][0]*20,3,$vobserv,0,'J');
                
               
		
		
                
                $lh = $lh +40;
		
		$ls=-5;
		$this->SetFont('arial','B',8);
                $this->SetFillColor(188,217,190); //verde agua
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*12,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*12,3,  utf8_decode( 'Denominación Moneda'),0,'C');
                
                
                $ls = $colSubCab[0][0]*12-5;
                $this->SetFillColor(188,217,190); //verde agua
                $this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*4,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*4,3,'Cantidad',0,'C');
                
                $ls = $colSubCab[0][0]*16-5;
                $this->SetFillColor(188,217,190); //verde agua
                $this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*4,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*4,3,'Total',0,'C');
		
                
		

		
	}
	
	function Footer(){
		global $marini;
		global $nro_nec;
		global $ano_eje;
		global $nombreGispAdmincon;
		//Posición: a 1,5 cm del final
		$this->SetXY($marini,-15);
		//Arial italic 8
		$this->SetFont('Arial','',10);
		//Número de página
		$this->Cell(79,5,'Municipalidad Distrital de Puente Piedra',0,0,'L',0);
		$this->SetFont('Arial','',8);
		$this->SetXY($marini,-10);
		$this->Cell(0,5,utf8_decode('Pagina N° ').$this->PageNo().' de {nb}',0,0,'R');
		$this->SetXY($marini,-10);
		$this->Cell(79,5,'GIT - Gestor Integrado Tributario',0,0,'L',0);
		
	}
	
	function WriteResumen($x,$h,$topmar, $corte){
		//datos SQL
		global $Coneccion;
		global $ano_eje;
		global $nro_nec;

		//datos DOC
		global $marini;
		global $topmar;
		global $repositorioFirmas;
                global $fechaFin;
                global $fechaIni;
                global $cajero2;
                global $cajero3;
                global $ConeccionRatania;
                global $cidUser;
                global $ccajero;
                global $usuarioCaja;
                
		

		
		if($h >= 210){
                    $corte = $this->CheckPageBreak(261);
			if($corte){
				$this->SetXY(15,$topmar + 5);
				//$this->Write(12,'corte 1');
			}/*
                          else{
				$this->SetXY(15,$h + 10);
				//$this->Write(10,'corte 0');
			}*/
		}else{
			$this->SetXY(15,$h + 5);
			//$this->Write(12,'corte 3');
		}

		$style = array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '0', 'phase' => 10, 'color' => array(0,0,0));
		$this->Line(0, 0, 1, 0, $style);
		
                
                
		$this->SetFont('Arial','B',9);
		$this->Cell(170,4,'RESUMEN',1,1,'C',0);
		$this->SetX(15);
		$this->Cell(20,4,'TIPO',1,0,'C',0);
		$this->Cell(110,4,  utf8_decode ('DESCRIPCIÓN'),1,0,'C',0);
		$this->Cell(40,4,'MONTO',1,1,'C',0);
		
		$Rs_grabar2 = new TSPResult($ConeccionRatania,"");
                $Rs_grabar2->Poner_MSQL(" 
                SELECT sum(t1.nmontot) as monto,
                t1.ctippag,
                (SELECT t2.vdescri
                FROM public.mconten as t2
                WHERE t2.idsigma=t1.ctippag
                ) as tipopago
                FROM tesoreria.dtesore as t1
                WHERE dfecpag >='".$fechaIni." 00:00:00' AND dfecpag <='".$fechaFin." 23:59:59'
                AND t1.vusernm  like '".$ccajero."%'
                    AND t1.nestado='1'
                GROUP BY tipopago,t1.ctippag;

                ");
                $Rs_grabar2->pg_Poner_Esquema("tesoreria");

                $Rs_grabar2->executeMSQL();



               // echo "<br><br>CONSULTA REQ UPDATE <br> ".$Rs_grabar2->Escribir_Consulta();			
                //$row= $Rs_grabar2->pg_Get_Row();
                $montoTotal = 0;
                $NN=0;
                $TotalResumen = $Rs_grabar2->pg_Num_Rows();
		while($NN<$TotalResumen){
			$row= $Rs_grabar2->pg_Get_Row();
			
			$monto= $row['monto'];
                        $montoTotal = $montoTotal+$monto;
                       /* if(trim($row['ctippag'])=='1000001884'){
                            $monto = -1*$monto;
                        }*/
                        $this->SetFont('Arial','',9);
			$this->SetX(15);
			$this->Cell(20,4,$row['ctippag'],1,0,'L',0);
			$this->Cell(110,4,$row['tipopago'],1,0,'L',0);
			$this->Cell(40,4,  number_format( $monto,2,',',' '),1,1,'R',0);
			
			////////////////////////////
			$var1 = $this->GetY();
			
			if($corte = $this->CheckPageBreak($var1)){
				$this->SetY($topmar + 10);
				$flag = 1;
			}else{
				$flag = 0;
			}
                        $Rs_grabar2->pg_Move_Next();
                        $NN++;
		}
                
                if($TotalResumen>0){
                    $Rs_grabar2 = new TSPResult($ConeccionRatania,"");
                    $Rs_grabar2->Poner_MSQL(" 
                    SELECT sum(t1.nmontot) as monto,
                    '' as ctippag,
                    'ANULADO' as tipopago
                    FROM tesoreria.mtesore as t1
                    WHERE dfecpag >='".$fechaIni." 00:00:00' AND dfecpag <='".$fechaFin." 23:59:59'
                    AND trim(t1.vusernm) like '".trim($usuarioCaja)."%'
                    AND t1.nestado='0'
                    GROUP BY 2,3;

                    ");
                    $Rs_grabar2->pg_Poner_Esquema("tesoreria");

                    $Rs_grabar2->executeMSQL();
                    //echo "<br><br>CONSULTA REQ UPDATE <br> ".$Rs_grabar2->Escribir_Consulta();
                    $monto=0;
                    if($Rs_grabar2->pg_Num_Rows()>0){
                        $row= $Rs_grabar2->pg_Get_Row();

                        $monto = floatval($row['monto']);
                        $this->SetFont('Arial','',9);
                        $this->SetX(15);
                        $this->Cell(20,4,'',1,0,'L',0);
                        $this->Cell(110,4,$row['tipopago'],1,0,'L',0);
                        $this->Cell(40,4,  number_format( -1*$monto,2,',',' '),1,1,'R',0);
                    }

                    $montoTotal = $montoTotal - $monto;
                    $this->SetFont('Arial','',9);
                    $this->SetX(15);
                    $this->Cell(130,4,'Total',1,0,'L',0);
                    $this->Cell(40,4,  number_format( $montoTotal,2,',',' '),1,1,'R',0);
                }
		
		
		return $flag;
	}
	
	function CheckPageBreak($h){
		if($h >= 260){
			$this->AddPage();	
			return 1;
		}else{
			$this->SetY($h);
			return 0;
		}
		/*if($h >= 250){
			$this->AddPage('P','mm','A4');
			return true;
		}*/
	}
	
	
}


$usuario = $_GET['P_USERIMPR'];
$cajero =  $_GET['P_NROCAJA'];
$cidUser =  trim($_GET['P_CIDUSER']);
$p_usernm =  $_GET['P_USERNM'];
$cajero2 = $cajero;
$fechaIni=$_GET['P_FECHADESDE'];
$fechaFin=$_GET['P_FECHAHASTA'];
$subTipoReporte = 'CUADRE DE CAJA DE CAJERO';
$tipoReporte = 'REPORTE DE INGRESOS POR CAJERO';


$pdf = new PDF('P','mm','A4');
$pdf->SetDisplayMode('fullpage');


if($cidUser=='' or !isset($cidUser) or $cidUser=='undefined'){
    $cidUser ='%';
}

$Rs_grabarCAB = new TSPResult($ConeccionRatania,"");
$Rs_grabarCAB->Poner_MSQL(" SELECT 
t4.idsigma,
t4.ciduser,t4.cnrocaj,
(t6.vpatern||' '||t6.vmatern||' '||t6.vnombre) as nombreccajero,
t4.cnumini,t4.cnumfin,
t4.nmonape,t4.nmonval,
t4.nmonanu,t4.nmonent,t4.nmondif,
t4.vobserv,
to_char(t4.dfecpro,'dd/mm/YYYY HH:mi:SS' ) as fechaapertura,
to_char(t4.ddatetm ,'dd/mm/YYYY HH:mi:SS' ) as fechacierre,
t7.ccajero,
t5.usuario
 from 
tesoreria.aperturacaja as t4,
seguridad.usuario as t5,
public.mperson as t6,
tesoreria.mcajero as t7
where 
t5.cidusuario=t4.ciduser
AND t5.cidpers=t6.idsigma
AND t7.ciduser=t5.cidusuario
 AND t4.dfecpro >='".$fechaIni." 00:00:00' AND t4.dfecpro <='".$fechaFin." 23:59:59'
AND t7.ciduser  like '".$cidUser."'

ORDER BY t4.cnrocaj

");
$Rs_grabarCAB->pg_Poner_Esquema("tesoreria");

$Rs_grabarCAB->executeMSQL();


//echo "<br><br>CONSULTA REQ UPDATE <br> ".$Rs_grabarCAB->Escribir_Consulta();

$NCAB = 0;
$numRowsCAB = $Rs_grabarCAB->pg_Num_Rows();
$rowCAB= $Rs_grabarCAB->pg_Get_Row();
$p_cperiod = $p_cperiod3;
//$NPeriodos=1;
//echo $numRowsCAB;
while($NCAB < $numRowsCAB){

    


$RUC='20131366702';
$numero_recibo='860100100014';

$rowCab= $Rs_grabarCAB->pg_Get_Row(); 
$idApertura=$rowCab['idsigma'];
$nroCaja=$rowCab['cnrocaj'];
$usuarioCaja=$rowCab['usuario'];
$nombreccajero=$rowCab['nombreccajero'];
$cnumini=$rowCab['cnumini'];
$cnumfin=$rowCab['cnumfin'];
$nmonape=$rowCab['nmonape'];
$nmonval=$rowCab['nmonval']; 
$nmonanu=$rowCab['nmonanu']; 
$nmonent=$rowCab['nmonent']; 
$nmondif=$rowCab['nmondif']; 
$vobserv=  utf8_decode( trim($rowCab['vobserv']) ); 
$fechaapertura=$rowCab['fechaapertura']; 
$fechacierre=$rowCab['fechacierre'];
$cidUser=$rowCab['ciduser'];
$ccajero=$rowCab['ccajero'];


$Rs_grabar2 = new TSPResult($ConeccionRatania,"");
$Rs_grabar2->Poner_MSQL(" 
SELECT sum(t1.nmontot) as monto
FROM tesoreria.mtesore as t1
WHERE dfecpag >='".$fechaIni." 00:00:00' AND dfecpag <='".$fechaIni." 23:59:59'
AND trim(t1.vusernm) = '".trim($usuarioCaja)."'
AND t1.nestado='0'
AND t1.cidapertura='".$idApertura."'  ;

");
$Rs_grabar2->pg_Poner_Esquema("tesoreria");
$Rs_grabar2->executeMSQL();
$row = $Rs_grabar2->pg_Get_Row();
$TotalAnulado = $row['monto'];

$Rs_grabar2 = new TSPResult($ConeccionRatania,"");
$Rs_grabar2->Poner_MSQL("SELECT sum(t1.nmontot) as monto FROM tesoreria.mtesore as t1 
	WHERE dfecpag >='".$fechaIni." 00:00:00' AND dfecpag <='".$fechaIni." 23:59:59'
			AND trim(t1.vusernm) = '".trim($usuarioCaja)."'
			AND t1.cidapertura='".$idApertura."' ; ");
$Rs_grabar2->pg_Poner_Esquema("tesoreria");
$Rs_grabar2->executeMSQL();
$row = $Rs_grabar2->pg_Get_Row();
$TotalOpe = $row['monto'];


$Rs_grabar = new TSPResult($ConeccionRatania,"");
$Rs_grabar->Poner_MSQL("SELECT 
sum(t1.ntotals) as monto
 from tesoreria.dvalmon as t1
where 
/*t1.aperturacaja='".$idApertura."'*/
t1.dfecpro >='".$fechaIni." 00:00:00' AND t1.dfecpro <='".$fechaIni." 23:59:59'    
AND trim(t1.vusernm) = '".trim($usuarioCaja)."'   
AND t1.ncantid>0
AND t1.aperturacaja='".$idApertura."' ;
");
$Rs_grabar->pg_Poner_Esquema("tesoreria");

$Rs_grabar->executeMSQL();
$row = $Rs_grabar->pg_Get_Row();
$TotalEfectivo = $row['monto'];
//echo $Rs_grabar->Escribir_Consulta();

$Rs_grabar = new TSPResult($ConeccionRatania,"");
/*
$Rs_grabar->Poner_MSQL("SELECT sum(t1.nmontot) as monto
 FROM tesoreria.dtesore as t1 
 WHERE t1.dfecpag >='".$fechaIni." 00:00:00' AND t1.dfecpag <='".$fechaIni." 23:59:59'
 AND t1.vusernm  like '".$ccajero."%' 
 AND t1.cnumope not IN
 (select t4.cnumope
 FROM tesoreria.mtesore as t4
 WHERE    t4.dfecpag >='".$fechaIni." 00:00:00' AND t4.dfecpag <='".$fechaIni." 23:59:59'
AND t4.vusernm  like '".$usuarioCaja."%'
 AND t4.nestado='0'
 GROUP BY t4.cnumope) 
 AND t1.ctippag not in ('1000001864','1000001884')

");
*/

$Rs_grabar->Poner_MSQL("SELECT sum(t1.nmontot -
coalesce((select sum(t4.nmontot) FROM tesoreria.mtesore as t4
 WHERE t4.cnumope=t1.cnumope
AND t4.nestado='0' 
 GROUP BY t4.cnumope), 0)) as monto
 FROM tesoreria.dtesore as t1 
 WHERE t1.dfecpag >='".$fechaIni." 00:00:00' AND t1.dfecpag <='".$fechaIni." 23:59:59'
 AND t1.vusernm  like '".$ccajero."%' 
 AND t1.ctippag not in ('1000001864','1000001884')

");

$Rs_grabar->pg_Poner_Esquema("tesoreria");

$Rs_grabar->executeMSQL();
$row = $Rs_grabar->pg_Get_Row();
$TotalNEfectivo = $row['monto'];


//$cajero='NDIESTRO';
//$usuario='NDIESTRO';
//$fechaEmision='12-12-2013 15:56';

//echo 'HOLA '.$fechaProyectado ;
//echo 'USUARIO '.$usuario ;


date_default_timezone_set('America/Lima');
$fechaImpresion="19/06/2014 17:45:59"; 
//$fechaImpresion=strftime('%d/%m/%Y %H:%M:%S'); 
$nroDoc='42215638';
//$fechaProyectado = '13/12/2013';
//$fechaRecargos = '13/12/2013';
if (!in_array($err, array('L', 'M', 'Q', 'H'))) $err = 'Q';

$colCab = array('61','105','51','25','220','110');
$colSubCab[0] = array('10','8','18');
$colSubCab[1] = array('18','20','25');
$colSubCab[2] = array('18','8','25');

$topIni = 10;
$marIni = 10; 
$topmar = 130;
//$lw=10;


//$pdf->AutoPrint();
//$pdf->AutoPrint();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);


$var1 = $pdf->GetY()+2;
//$var1 = $topmar+5;
$pdf->SetXY($lw,$lh = $var1);

/*
 SELECT 
t1.ctipope as tipo_operacion,
(SELECT t3.vdescri
FROM public.mconten as t3
WHERE t3.idsigma=t1.ctipmon) as tipo_moneda,
(SELECT t3.vobserv
FROM public.mconten as t3
WHERE t3.idsigma=t1.ctipmon)::NUMERIC as denominacion,
t1.ncantid,t1.ntotals,t1.ctipmon
 from tesoreria.dvalmon as t1
where 
t1.aperturacaja='0000002256'
AND t1.ncantid>0
ORDER BY 3 asc
 */

$Rs_grabar = new TSPResult($ConeccionRatania,"");
$Rs_grabar->Poner_MSQL("SELECT 
t1.ctipope as tipo_operacion,
(SELECT t3.vdescri
FROM public.mconten as t3
WHERE t3.idsigma=t1.ctipmon) as tipo_moneda,
(SELECT t3.vobserv
FROM public.mconten as t3
WHERE t3.idsigma=t1.ctipmon)::NUMERIC as denominacion,
t1.ncantid,t1.ntotals,t1.ctipmon
 from tesoreria.dvalmon as t1
where 
t1.aperturacaja='".$idApertura."'
AND t1.ncantid>0
ORDER BY t1.ctipmon asc

");
$Rs_grabar->pg_Poner_Esquema("tesoreria");

$Rs_grabar->executeMSQL();

	$N = 0;
	$numRows = $Rs_grabar->pg_Num_Rows();
	
	$tipoIngreso = "###";
	$codPar = "####";
	$predioContrib= "####";
	
        
        $sumTotalEfectivo = 0;
        
	
	while($N < $numRows){
		
		$row= $Rs_grabar->pg_Get_Row();
                $lz=0;
                $ls=-5;
                $lw=$marIni;
		//echo "TIPO INGRESO ".$row['ctiping']." - ".$tipoIngreso."<br>";
		
			
				$ls=-5;
				$pdf->SetFont('arial','',8);
				$pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colSubCab[0][0]*12,3,utf8_decode($row['tipo_moneda']),0,'J');
				
                                $ls = $colSubCab[0][0]*12 -5;
                                $pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colSubCab[0][0]*4,3, number_format($row['ncantid'],2,',',' '),0,'R');
				
				$ls = $colSubCab[0][0]*16 -5;
				
                                $pdf->SetFont('arial','',8);
				$pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colSubCab[0][0]*4,3,number_format($row['ntotals'],2,',',' '),0,'R');
                                
                                
				
				$var1 = $pdf->GetY();
				if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;
			
			
				$sumTotalEfectivo += $row['ntotals'];
			      
			$Rs_grabar->pg_Move_Next();
                        
			
			
                        $lh += $lz+4;
                        $lz =0;
			
			
			
			$N++;
		}
		
      
               
            //Sub Total Por Año
            //$lh += 3;
                /*$var1 = $pdf->GetY();
                if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;*/
                $lw=$marIni;
                $lz += 0;
		$ls=-5;    
                $pdf->SetFont('arial','B',10);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                //$pdf->Line($lw+$ls, $lh+4, 205, $lh +4, $style);


                //$pdf->Line($lw+$ls, $lh+$ls, 210, $lh +$ls, $style);
                $ls=-5;
                $pdf->SetFont('arial','',8);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*12,3,utf8_decode('TOTAL EFECTIVO'),1,'J');

                $ls = $colSubCab[0][0]*12 -5;
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*4,3, '',1,'R');

                $ls = $colSubCab[0][0]*16 -5;

                $pdf->SetFont('arial','',8);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*4,3,number_format($sumTotalEfectivo,2,',',' '),1,'R');




                $var1 = $pdf->GetY();
                if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;	
                
               $lh += $lz+4;
                 $lz =0;
                        
                 $Rs_grabar = new TSPResult($ConeccionRatania,"");
$Rs_grabar->Poner_MSQL("SELECT sum(t1.nmontot) as monto,
              (case  
			when ctiprec in ('0000000273','0000002120') then 'PREDIAL' 
			when ctiprec in('0000000279', '0000000283', '0000007267','0000008509',
					'0000002123', '0000002124', '0000002125','0000002126','0000007931') then 'ARBITRIOS' 
			when ctiprec in('0000000312') then 'F'
			else 'OTROS' end )  as controlpago,t1.cnumcom,t1.vobserv
                FROM tesoreria.mtesore as t1
                WHERE  t1.dfecpag >='".$fechaIni." 00:00:00' AND t1.dfecpag <='".$fechaFin." 23:59:59'
                    AND t1.vusernm  like '".$usuarioCaja."%'
                    AND t1.nestado='0'
                GROUP BY controlpago,t1.ctippag,t1.cnumcom,t1.vobserv;

");
$Rs_grabar->pg_Poner_Esquema("tesoreria");

$Rs_grabar->executeMSQL();
//echo "<br><br>CONSULTA REQ UPDATE <br> ".$Rs_grabar->Escribir_Consulta();

	$N = 0;
	$numRows = $Rs_grabar->pg_Num_Rows();
	
	$tipoIngreso = "###";
	$codPar = "####";
	$predioContrib= "####";
	
        
        $sumTotalAnulado = 0;
        
	
	while($N < $numRows){
		
		$row= $Rs_grabar->pg_Get_Row();
                $lz=0;
                $ls=-5;
                $lw=$marIni;
		//echo "TIPO INGRESO ".$row['ctiping']." - ".$tipoIngreso."<br>";
		
			
				$ls=-5;
				$pdf->SetFont('arial','',6);
				$pdf->SetXY($lw+$ls,$lh+$lz);
                                $denominacionNoEfectivo = $row['tipopago'].' Recibo '.$row['cnumcom'].' Tipo '.$row['controlpago'].' - '.$row['vobserv'];
				$denominacionNoEfectivo = ereg_replace("<p>", "",$denominacionNoEfectivo);
                                $denominacionNoEfectivo = ereg_replace("</p>", "",$denominacionNoEfectivo);
                                $denominacionNoEfectivo = ereg_replace("[\n|\r|\n\r]", " ", $denominacionNoEfectivo);
                                $pdf->MultiCell($colSubCab[0][0]*12,3,utf8_decode($denominacionNoEfectivo),0,'J');
				
                                $pdf->SetFont('arial','',8);
                                $ls = $colSubCab[0][0]*12 -5;
                                $pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colSubCab[0][0]*4,3, number_format('1',2,',',' '),0,'R');
				
				$ls = $colSubCab[0][0]*16 -5;
				
                                $pdf->SetFont('arial','',8);
				$pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colSubCab[0][0]*4,3,number_format($row['monto'],2,',',' '),0,'R');
                                
                                
				
				$var1 = $pdf->GetY();
				if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;
			
			
				$sumTotalAnulado += $row['monto'];
			      
			$Rs_grabar->pg_Move_Next();
                        
			
			
                        $lh += $lz+8;
                        $lz =0;
			
			
			
			$N++;
		}
		
      
               
            //Sub Total Por Año
            //$lh += 3;
                /*$var1 = $pdf->GetY();
                if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;*/
                $lw=$marIni;
                $lz += 0;
		$ls=-5;    
                $pdf->SetFont('arial','B',10);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                //$pdf->Line($lw+$ls, $lh+4, 205, $lh +4, $style);


                //$pdf->Line($lw+$ls, $lh+$ls, 210, $lh +$ls, $style);
                $ls=-5;
                $pdf->SetFont('arial','',8);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*12,3,utf8_decode('TOTAL ANULADO'),1,'J');

                $ls = $colSubCab[0][0]*12 -5;
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*4,3, '',1,'R');

                $ls = $colSubCab[0][0]*16 -5;

                $pdf->SetFont('arial','',8);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*4,3,number_format($sumTotalAnulado,2,',',' '),1,'R');
 
                 
                 
                 $lh += $lz+4;
                 $lz =0;
 $Rs_grabar = new TSPResult($ConeccionRatania,"");
 /*                       
                 
$Rs_grabar->Poner_MSQL("SELECT t1.nmontot as monto,
 t1.ctippag, (SELECT t2.vdescri 
 FROM public.mconten as t2 
 WHERE t2.idsigma=t1.ctippag ) as tipopago ,
 t1.cnumope,t1.dnrodoc,t1.nnroope
 FROM tesoreria.dtesore as t1 
 WHERE t1.dfecpag >='".$fechaIni." 00:00:00' AND t1.dfecpag <='".$fechaFin." 23:59:59'
 AND t1.vusernm  like '".$ccajero."%' 
 AND t1.cnumope not IN
 (select t4.cnumope
 FROM tesoreria.mtesore as t4
 WHERE    t4.dfecpag >='".$fechaIni." 00:00:00' AND t4.dfecpag <='".$fechaFin." 23:59:59'
AND t4.vusernm  like '".$usuarioCaja."%'
 AND t4.nestado='0'
 GROUP BY t4.cnumope) 

 AND t1.ctippag not in ('1000001864','1000001884')

");
*/

$Rs_grabar->Poner_MSQL("SELECT 
( t1.nmontot -
coalesce((select sum(t4.nmontot) FROM tesoreria.mtesore as t4
 WHERE t4.cnumope=t1.cnumope
AND t4.nestado='0' 
 GROUP BY t4.cnumope), 0) ) as monto, t1.ctippag, 
(SELECT t2.vdescri FROM public.mconten as t2 WHERE t2.idsigma=t1.ctippag ) as tipopago , 
t1.cnumope,t1.dnrodoc,t1.nnroope FROM tesoreria.dtesore as t1
 WHERE t1.dfecpag >='".$fechaIni." 00:00:00' AND t1.dfecpag <='".$fechaFin." 23:59:59'
 AND t1.vusernm  like '".$ccajero."%' 
 AND t1.ctippag not in ('1000001864','1000001884')

");
$Rs_grabar->pg_Poner_Esquema("tesoreria");

$Rs_grabar->executeMSQL();
//echo "<br><br>CONSULTA REQ UPDATE <br> ".$Rs_grabar->Escribir_Consulta();

	$N = 0;
	$numRows = $Rs_grabar->pg_Num_Rows();
	
	$tipoIngreso = "###";
	$codPar = "####";
	$predioContrib= "####";
	
        
        $sumTotalNoEfectivo = 0;
        
	
	while($N < $numRows){
		
		$row= $Rs_grabar->pg_Get_Row();
                $lz=0;
                $ls=-5;
                $lw=$marIni;
		//echo "TIPO INGRESO ".$row['ctiping']." - ".$tipoIngreso."<br>";
		
			
				$ls=-5;
				$pdf->SetFont('arial','',6);
				$pdf->SetXY($lw+$ls,$lh+$lz);
                                $denominacionNoEfectivo = $row['tipopago'].' N° Doc '.$row['dnrodoc'].'N° Ope '.$row['nnroope'];
				$pdf->MultiCell($colSubCab[0][0]*12,3,utf8_decode($denominacionNoEfectivo),0,'J');
				
                                $pdf->SetFont('arial','',8);
                                $ls = $colSubCab[0][0]*12 -5;
                                $pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colSubCab[0][0]*4,3, number_format('1',2,',',' '),0,'R');
				
				$ls = $colSubCab[0][0]*16 -5;
				
                                $pdf->SetFont('arial','',8);
				$pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colSubCab[0][0]*4,3,number_format($row['monto'],2,',',' '),0,'R');
                                
                                
				
				$var1 = $pdf->GetY();
				if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;
			
			
				$sumTotalNoEfectivo += $row['monto'];
			      
			$Rs_grabar->pg_Move_Next();
                        
			
			
                        $lh += $lz+4;
                        $lz =0;
			
			
			
			$N++;
		}
		
      
               
            //Sub Total Por Año
            //$lh += 3;
                /*$var1 = $pdf->GetY();
                if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;*/
                $lw=$marIni;
                $lz += 0;
		$ls=-5;    
                $pdf->SetFont('arial','B',10);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                //$pdf->Line($lw+$ls, $lh+4, 205, $lh +4, $style);


                //$pdf->Line($lw+$ls, $lh+$ls, 210, $lh +$ls, $style);
                $ls=-5;
                $pdf->SetFont('arial','',8);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*12,3,utf8_decode('TOTAL NO EFECTIVO'),1,'J');

                $ls = $colSubCab[0][0]*12 -5;
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*4,3, '',1,'R');

                $ls = $colSubCab[0][0]*16 -5;

                $pdf->SetFont('arial','',8);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*4,3,number_format($sumTotalNoEfectivo,2,',',' '),1,'R');

                $ls=-5;
                $lh += $lz+4;
                $pdf->SetFont('arial','',8);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*12,3,utf8_decode('TOTAL A REPORTAR'),1,'J');

                $ls = $colSubCab[0][0]*12 -5;
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*4,3, '',1,'R');

                $ls = $colSubCab[0][0]*16 -5;

                $pdf->SetFont('arial','',8);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colSubCab[0][0]*4,3,number_format($sumTotalEfectivo+$sumTotalNoEfectivo,2,',',' '),1,'R');


                $var1 = $pdf->GetY();
                if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;	

		// $corte = $pdf->WriteResumen($ls,$lh+10,$topmar, 1);

$Rs_grabarCAB->pg_Move_Next();
	$NCAB++;
}                 
                 

$pdf->Output();


?>